package com.cmsz.shuang.booter.rpc;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Proxy {
	private Object actor; //  被代理的服务对象
	private Class clazz;	// 被代理的接口
	private String interfaceName; // 接口名
	
	
	public String getInterfaceName() {
		return interfaceName;
	}

	public void setInterfaceName(String interfaceName) {
		this.interfaceName = interfaceName;
	}

	public Object getActor() {
		return actor;
	}
	
	/**
	 * 设置被代理的服务类，该类部署在服务端，提供具体的服务
	 * @param actor
	 */
	public void setActor(Object actor) {
		this.actor = actor;
	}

	public Class getClazz() {
		return clazz;
	}
	
	/**
	 * 设置代理的接口类型
	 * @param clazz
	 */
	public void setClazz(Class clazz) {
		this.clazz = clazz;
	}
	
	public Object call(String methodName,Class[] parameterTypes, Object[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Method method=clazz.getMethod(methodName, parameterTypes);
		return method.invoke(actor, args);
	}
	
}
